package com.ruoyi.ufox.service.impl;



import com.ruoyi.ufox.domain.BisDeviceDataDay;
import com.ruoyi.ufox.mapper.BisDeviceDataDayMapper;
import com.ruoyi.ufox.service.IBisDeviceDataDayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;


/**
 * 数据日统计Service业务层处理
 * 
 * @author ufoxs
 * @date 2022-08-17
 */
@Service
public class BisDeviceDataDayServiceImpl implements IBisDeviceDataDayService
{
    @Autowired
    private BisDeviceDataDayMapper bisDeviceDataDayMapper;

    /**
     * 查询数据日统计
     * 
     * @param recordId 数据日统计主键
     * @return 数据日统计
     */
    @Override
    public BisDeviceDataDay selectBisDeviceDataDayByRecordId(Long recordId)
    {
        return bisDeviceDataDayMapper.selectBisDeviceDataDayByRecordId(recordId);
    }

    /**
     * 查询数据日统计列表
     * 
     * @param bisDeviceDataDay 数据日统计
     * @return 数据日统计
     */
    @Override
    public List<BisDeviceDataDay> selectBisDeviceDataDayList(BisDeviceDataDay bisDeviceDataDay)
    {
        return bisDeviceDataDayMapper.selectBisDeviceDataDayList(bisDeviceDataDay);
    }

    /**
     * 新增数据日统计
     * 
     * @param bisDeviceDataDay 数据日统计
     * @return 结果
     */
    @Override
    public int insertBisDeviceDataDay(BisDeviceDataDay bisDeviceDataDay)
    {
        return bisDeviceDataDayMapper.insertBisDeviceDataDay(bisDeviceDataDay);
    }

    /**
     * 修改数据日统计
     * 
     * @param bisDeviceDataDay 数据日统计
     * @return 结果
     */
    @Override
    public int updateBisDeviceDataDay(BisDeviceDataDay bisDeviceDataDay)
    {
        return bisDeviceDataDayMapper.updateBisDeviceDataDay(bisDeviceDataDay);
    }

    /**
     * 批量删除数据日统计
     * 
     * @param recordIds 需要删除的数据日统计主键
     * @return 结果
     */
    @Override
    public int deleteBisDeviceDataDayByRecordIds(Long[] recordIds)
    {
        return bisDeviceDataDayMapper.deleteBisDeviceDataDayByRecordIds(recordIds);
    }

    /**
     * 删除数据日统计信息
     * 
     * @param recordId 数据日统计主键
     * @return 结果
     */
    @Override
    public int deleteBisDeviceDataDayByRecordId(Long recordId)
    {
        return bisDeviceDataDayMapper.deleteBisDeviceDataDayByRecordId(recordId);
    }

    @Override
    public List<BisDeviceDataDay> getTimg(String deviceCode,String date) {
        List<BisDeviceDataDay> list=this.bisDeviceDataDayMapper.getTimg(deviceCode,date);
        for (int i = 1; i <=24;i++){
            boolean aa=false;
            for (BisDeviceDataDay ltem: list) {
                if (i == ltem.getHour().intValue()){
                aa=true;
                break;
                }
            }
            if (aa==false) {
                BisDeviceDataDay dataDay=new BisDeviceDataDay();
                dataDay.setHour((long) i);
                dataDay.setTemperature(BigDecimal.valueOf(0));
                dataDay.setHumidity(BigDecimal.valueOf(0));
                dataDay.setLightIntensity(BigDecimal.valueOf(0));
                list.add(i-1,dataDay);

            }
        }
        return list;
    }
}
